package com.gblog.gblog.controller;


import com.gblog.gblog.entity.Article;
import com.gblog.gblog.service.ArticleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yixin
 * @since 2024-05-07
 */
@Slf4j
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("/list")
    public List<Article> getArticlesByUid() {

        return null;
    }

    @GetMapping("/{id}")
    public Article getArticleById(@PathVariable Integer id) {

//        LambdaQueryWrapper<Article> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        lambdaQueryWrapper.eq(Article::getId, id);
//        Article article = articleService.getOne(lambdaQueryWrapper);
        log.info(id.toString());
        Article article = articleService.getById(id);
        if (article == null) {
//todo: 报错
            return null;
        }
        return article;
    }
}

